package com.hospital.doctor.doctorg.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.hospital.doctor.doctorg.entity.QueueEntity;
import com.hospital.doctor.doctorg.service.QueueService;
import com.hospital.doctor.doctorh.entity.PatientInfo;
import com.hospital.doctor.doctorh.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName: TotalbillController
 * @description：
 * @author：TanKai
 * @date：2021/9/17 14:53
 * @versions：v1.0
 */
@Controller
@RequestMapping("/doctorg")
public class QueueController {

    @Autowired
    private QueueService queueService;

    @Autowired
    private DoctorService doctorService;

    //医院介绍界面
    @RequestMapping("/index")
    public String index() {
        return "doctor/menu";
    }

    //医院菜单框架
    @RequestMapping("/menu")
    public String menu() {
        return "menu";
    }


    @RequestMapping("/selPatient")
    private String cxs(Model model, Integer doctorId, @RequestParam(defaultValue = "") String name, @RequestParam(defaultValue = "1") Integer pageNum) {
        List<PatientInfo> pats = doctorService.selPat(doctorId, 1, 5);
        PageInfo<PatientInfo> page = new PageInfo<>(pats);

        PageInfo<QueueEntity> list = queueService.getList(doctorId, name, pageNum);

        model.addAttribute("pat", page);
        model.addAttribute("page", list);
        list.getList().forEach(System.out::println);
        model.addAttribute("name", name);
        return "doctor/check";
    }

    @RequestMapping("/update")
    @ResponseBody
    public String gxs(Model model, int id, String name) {
        Boolean b = queueService.stateUpdate(id);
        return JSON.toJSONString(b);
    }


}
